package com.atguigu.ggkt.wechat.config;

import com.atguigu.ggkt.utils.SpringTool;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class WxMpServicePostProcessor implements BeanPostProcessor {

    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof WxMpService) {
            WxMpService wxMpService = (WxMpService) bean;
            WxMpConfigStorage wxMpConfigStorage = SpringTool.getSpringBean("wxMpConfigStorage");
            wxMpService.setWxMpConfigStorage(wxMpConfigStorage);
        }
        return bean;
    }
}
